package com.fdb.efp.nls.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.PspBillListDao;
import com.fdb.efp.nls.service.domain.PspBillList;
import com.fdb.efp.nls.service.facade.PspBillListService;
import com.fdb.efp.nls.service.vo.PspBillListVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 贷后检查借据表				<p>
 * @author chenqm1
 * @date 2018-05-05
 */
@Service("pspBillListService")
public class PspBillListServiceImpl implements PspBillListService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PspBillListServiceImpl.class);

	@Autowired
	private PspBillListDao pspBillListDao;
	
	/**
	 * 新增操作
	 */
	public int insertPspBillList(PspBillListVO inPspBillListVo) {
		logger.debug("当前新增数据为:"+ inPspBillListVo.toString());
		int num = 0;
		try {
			PspBillList pspBillList = new PspBillList();
			beanCopy(inPspBillListVo, pspBillList);
			num = pspBillListDao.insertPspBillList(pspBillList);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PspBillListVO inPspBillListVo) {
		logger.debug("当前删除数据条件为:"+ inPspBillListVo);
		int num = 0;
		try {
			PspBillList pspBillList = new PspBillList();
			beanCopy(inPspBillListVo, pspBillList);
			num = pspBillListDao.deleteByPk(pspBillList);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspBillListVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PspBillListVO inPspBillListVo) {
		logger.debug("当前修改数据为:"+ inPspBillListVo.toString());
		int num = 0;
		try {
			PspBillList pspBillList = new PspBillList();
			beanCopy(inPspBillListVo, pspBillList);
			num = pspBillListDao.updateByPk(pspBillList);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPspBillListVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PspBillListVO queryByPk(PspBillListVO inPspBillListVo) {
		
		logger.debug("当前查询参数信息为:"+ inPspBillListVo);
		try {
			PspBillList queryPspBillList = new PspBillList();
			beanCopy(inPspBillListVo, queryPspBillList);
			PspBillList queryRslPspBillList = pspBillListDao.queryByPk(queryPspBillList);
			if (Objects.nonNull(queryRslPspBillList)) {
				PspBillListVO outPspBillListVo = beanCopy(queryRslPspBillList, new PspBillListVO());
				logger.debug("当前查询结果为:"+ outPspBillListVo.toString());
				return outPspBillListVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspBillListVO> queryAllOwner(PspBillListVO pspBillListVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PspBillListVO> list = null;
		try {
			List<PspBillList> pspBillLists = pspBillListDao.queryAllOwnerByPage(pspBillListVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ pspBillLists.size());
			pageSet(pspBillLists, pspBillListVo);
			list = (List<PspBillListVO>) beansCopy(pspBillLists, PspBillListVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspBillListVO> queryAllCurrOrg(PspBillListVO pspBillListVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PspBillList> pspBillLists = pspBillListDao.queryAllCurrOrgByPage(pspBillListVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+pspBillLists.size());
		List<PspBillListVO> list = null;
		try {
			pageSet(pspBillLists, pspBillListVo);
			list = (List<PspBillListVO>) beansCopy(pspBillLists, PspBillListVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PspBillListVO> queryAllCurrDownOrg(PspBillListVO pspBillListVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PspBillList> pspBillLists = pspBillListDao.queryAllCurrDownOrgByPage(pspBillListVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ pspBillLists.size());
		List<PspBillListVO> list = null;
		try {
			pageSet(pspBillLists, pspBillListVo);
			list = (List<PspBillListVO>) beansCopy(pspBillLists, PspBillListVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}
	/**
	 * 批量插入数据
	 */
	@Override
	public int insertbatchPspBillList(List<PspBillListVO> pspBillLists) {
		logger.info("当前批量新增数据为:"+JSONObject.toJSONString(pspBillLists));
		int num = 0;
		List<PspBillList> pspBillList= null;
		try {
			pspBillList = (List<PspBillList>) beansCopy(pspBillLists, PspBillList.class);
			num = pspBillListDao.insertbatchPspBillList(pspBillList);
		} catch (Exception e) {
			logger.error("批量新增数据发生异常!", e);
			num = -1;
		}
		logger.info("当前批量新增数据条数为:"+ num);
		return num;
	}
}
